<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Bull extends JS_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model('bull_mdl');
	}

	public function index(){
		
	}

	/**
	 * 根据商铺查询详情
	 */
	public function shops_bull(){
		if($this->session->suser->group != 1){
			show_error('参数错误！');
		}

		$sid = $this->input->get('sid',TRUE);
		$sid = intval($sid);
		if(empty($sid)){
			show_error('参数错误！');
		}

		$this->db->where('shops_id',$sid);
		$list = $this->bull_mdl->select();
		$list = $this->bull_mdl->assembly($list);

		if(empty($list)){
			show_error('参数错误！');
		}

		$this->load->view('default/bull_shops_bull',['list' => $list]);
	}

	/**
	 * 根据用户详情
	 */
	public function shops_bull_user(){

		$sid = $this->input->get('sid',TRUE);
		$sid = intval($sid);
		if(empty($sid)){
			show_error('参数错误！');
		}

		//获取当前用户的等级权限
		$this->load->model('level_mdl');
		$this->db->where('group_id',$this->session->suser->level_id);
		$level = $this->level_mdl->get_one();

		$this->db->where('hierarchy >=',(int)$level['hierarchy']);
		$this->db->where('group_id !=',0);
		$list_level = $this->level_mdl->select();
		$map = [];
		foreach($list_level as $k => $v){
			$map[] = $v['id'];
		}

		$this->db->where('shops_id',$sid);
		$this->db->where_in('level_id',$map);
		$list = $this->bull_mdl->select();
		$list = $this->bull_mdl->assembly($list);


		if(empty($list)){
			show_error('参数错误！');
		}

		$this->load->view('default/bull_shops_bull',['list' => $list]);
	}

	//查询某一个用户的所有信息
	public function user_info(){
		$uid = $this->input->get('uid',TRUE);
		$uid = intval($uid);

		if(empty($uid)){
			show_error('参数错误！');
		}

		$this->db->where('uid',$uid);
		$this->db->select('id,shops_id,bull,s_time');
		$list = $this->bull_mdl->select();

		if(empty($list)){
			die('该用户没有下辖商铺数据');
		}
		
		$list = $this->bull_mdl->assembly($list);
		$this->load->view('default/bull_user_info.php',['list'=>$list]);

	}

}

/* End of file Bull.php */
/* Location: ./application/controllers/Bull.php */